﻿using JobSearcherAPI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace JobSearcherAPI.Search
{
    internal class DigitalGovSearcher : XmlSearcher
    {
        const string BASE_URL = "https://data.usajobs.gov/api/jobs?";
        const string TITLE = "Title=";
        const string LOCATION = "&LocationName=";
        const string KEYWORD = "&Keyword=";


        protected override string CreateSearchAddress(SearchArguments arguments)
        {
            stringBuilder.Clear()
                .Append(BASE_URL)
                .Append(TITLE).Append(arguments.Title.UrlEncoded())
                .Append(LOCATION).Append(arguments.Location.UrlEncoded())
                .Append(KEYWORD).Append(arguments.Keywords.UrlEncoded());
            return stringBuilder.ToString();
        }

        protected override void SetUpAttributeStrings()
        {
            title = "JobTitle";
            description = "JobSummary";
            location = "Locations";
            company = "AgencySubElement";
            date = "StartDate";
            url = "ApplyOnlineURL";
        }

        protected override XmlNodeList GetJobNodes()
        {
            return doc.SelectSingleNode("ResultsModel")
                      .SelectSingleNode("JobData")
                      .ChildNodes;
        }
    }
}
